package com.order.controller.admin;

import com.alibaba.druid.filter.logging.Slf4jLogFilter;
import com.order.result.Result;
import com.order.utils.AliOssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.order.constant.JwtClaimsConstant;
import com.order.dto.EmployeeDTO;
import com.order.dto.EmployeeLoginDTO;
import com.order.dto.EmployeePageQueryDTO;
import com.order.entity.Employee;
import com.order.properties.JwtProperties;
import com.order.result.PageResult;
import com.order.result.Result;
import com.order.service.EmployeeService;
import com.order.utils.JwtUtil;
import com.order.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.SplittableRandom;
import java.util.UUID;

@RestController
@RequestMapping("/admin/common")
@Api(tags="通用接口")
public class CurrencyController {
    @Autowired
    private AliOssUtil aliOssUtil;

    @PostMapping("/upload")
    @ApiOperation("文件上传")
    public Result<String> upload(MultipartFile file) {
        try {
            String originalFilename=file.getOriginalFilename();
            String substring = originalFilename.substring(originalFilename.lastIndexOf("."));
            String fName = UUID.randomUUID().toString() + substring;
            String uploadPath = null;
            uploadPath = aliOssUtil.upload(file.getBytes(), fName);
            return Result.success(uploadPath);
        } catch (IOException e) {
           e.printStackTrace();
        }
        return Result.error("文件上传失败");
    }
}
